package com.hospitalsystem.service.impl;

import com.hospitalsystem.dao.PatientRecordDao;
import com.hospitalsystem.entity.PatientRecord;
import com.hospitalsystem.service.PatientRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (PatientRecord)表服务实现类
 *
 * @author makejava
 * @since 2024-12-28 19:33:12
 */
@Service("patientRecordService")
public class PatientRecordServiceImpl implements PatientRecordService {
    @Resource
    private PatientRecordDao patientRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  pRId
     * @return 实例对象
     */
    @Override
    public PatientRecord queryById(String pRId) {
        return this.patientRecordDao.queryById(pRId);
    }

    /**
     * 分页查询
     *
     * @param patientRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PatientRecord> queryByPage(PatientRecord patientRecord, PageRequest pageRequest) {
        long total = this.patientRecordDao.count(patientRecord);
        return new PageImpl<>(this.patientRecordDao.queryAllByLimit(patientRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param patientRecord 实例对象
     * @return 实例对象
     */
    @Override
    public PatientRecord insert(PatientRecord patientRecord) {
        this.patientRecordDao.insert(patientRecord);
        return patientRecord;
    }

    /**
     * 修改数据
     *
     * @param patientRecord 实例对象
     * @return 实例对象
     */
    @Override
    public PatientRecord update(PatientRecord patientRecord) {
        this.patientRecordDao.update(patientRecord);
        return this.queryById(patientRecord.getPRId());
    }

    /**
     * 通过主键删除数据
     *
     * @param  pRId
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String pRId) {
        return this.patientRecordDao.deleteById(pRId) > 0;
    }
}
